package mhcs.client;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.ScrollPanel;

class LandingMap extends ScrollPanel implements MyListener {
    public LandingMap() {
        MHCS.dataSet.addListener(this);
        g = new Grid(50, 100);
        g.setCellPadding(0);
        g.setCellSpacing(0);
//        g.setBorderWidth(0);
//        g.setPixelSize(10, 10);
//        g.setSize("10px", "10px");
//        Image background = new Image("images/MarsModuleLandingArea.jpg");
//        background.setPixelSize(1000, 500);
//        add(background);
        add(g);
//        setWidth("1000px");
//        setHeight("500px");
        for (int row = 0; row < 50; row++) {
            for (int col = 0; col < 100; col++) {
                g.getCellFormatter().setStyleName(row, col, "g");
            }
        }
        markUnuseable();
        g.setStyleName("myGrid");
    }

    @Override
    public void actionPerformed(String action, Module module) {
        if (action.equals("clear")) {
            g.clear();
            markUnuseable();
        }
        if (action.equals("remove")) {
            g.clearCell(50 - module.getY(), module.getX() - 1);
        }
        if (action.equals("add")) {
            Image image = new Image("images/" + module.getType() + ".jpg");
            image.setPixelSize(20, 20);
            g.setWidget(50 - module.getY(), module.getX() - 1, image);
        }
    }
    
    private void markUnuseable() {
        for (int row = 0; row < 11; row++) {
            for (int col = 39; col < 50; col++) {
                Image image = new Image("images/Area.jpg");
                image.setPixelSize(20, 20);
                g.setWidget(row, col, image);
            }
        }
    }
    
    private Grid g;
}